package handler;

import aop.ServiceUtil;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author 肖地洋
 * @Date 2022/5/4 15:39
 */
public class MyInvocationHandler implements InvocationHandler {

    private Object target;
    public MyInvocationHandler(Object target){
        this.target = target;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        //通过代理对象执行方法时，会调用执行这个invoke();
        Object res = null;
        ServiceUtil.doLog();
        //执行目标类的方法，通过Method类实现
        res = method.invoke(target,args);
        ServiceUtil.doTrans();
        return res;
    }
}
